import { queryList as wellList, createOne as wellCreate } from "@/api/well/well.js";
import { getOne } from "@/api/salvage/threadCard.js";
// 地址匹配
export function getAddressInfo(address) {
  if (!address) {
    return null;
  }
  let withoutSpaces = address.replace(/\s/g, ""); // 去除空格
  let withoutParentheses = withoutSpaces.replace(/[\(（][^)）]*[\)）]/g, ""); // 去除括号及括号内的内容
  const match = withoutParentheses.match(
    /^(?<province>[^省]+省)?(?:\s*\([^)]+\))?\s*(?<city>[^市区]+[市区])?(?:\s*\([^)]+\))?\s*(?<county>[^县市区]+[县市区])?(?:\s*\([^)]+\))?/u
  );
  return match ? match.groups : null;
}

// 新建井存在判断
export function WellDatas(id, wellId) {
  var queryWell = { order: "DESC", pageNum: 1, pageSize: 100, sortBy: "id", searchKey: wellId };
  wellList(queryWell).then((res) => {
    console.log('WellDatas', res);
    if (res.content.length == 0) {
      console.log("不存在");
      var formWell = { id: id, wellId: wellId, wellName: wellId, latitude: 44, longitude: 124 };
      formWell.deptId = "2";
      // formWell.deptId = localStorage.getItem("userDeptId")
      console.log("新建井form", formWell);
      wellCreate(formWell).then((response) => {
        console.log("wellCreate", response);
        // $.showToast({
        //   title: "新建井成功",
        //   icon: "success",
        // });
      });
      // getOne(id).then((resOne) => {
      //   // console.log('getOne', resOne);
      //   const addressInfo = computed(() => {
      //     const { province = "", city = "", county = "" } = getAddressInfo(resOne.geographicalLocation) || {};
      //     return { province, city, county };
      //   });
      //   formWell.province = addressInfo.value.province;
      //   formWell.city = addressInfo.value.city;
      //   formWell.county = addressInfo.value.county;
      // }).then(() => {
      //   console.log("新建井form", formWell);
      //   wellCreate(formWell).then((response) => {
      //     console.log("wellCreate", response);
      //     $.showToast({
      //       title: "新建井成功",
      //       icon: "success",
      //     });
      //   });
      // });
    } else {
      console.log("存在");
    }
  });
}
